home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 25 / CU Amiga Magazine's Super CD-ROM 25 (1998)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1998-08].iso / CUCD / Utilities / Type1Manager / src / type1lib.c < prev    next >
C/C++ Source or Header  |  1998-05-16  |  7KB  |  286 lines

  1. /* type1lib.c
  2.  
  3.     Author - Amish S. Dave
  4.  
  5. This file contains the entry points of the Amiga shared library
  6. It calls functions in type1interface.c
  7.  
  8. */
  9.  
  10. /**
  11.  * INCLUDES
  12.  **/
  13. #include <proto/exec.h>
  14. #include <proto/dos.h>
  15. #include <proto/utility.h>
  16. #include <diskfont/glyph.h>
  17. #include <diskfont/diskfonttag.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20.  
  21. #define  OT_Spec2       (OT_Level1 | 0x102)
  22. #define  OT_Spec3       (OT_Level1 | 0x103)
  23.  
  24. #include "amishfontrequest.h"
  25.  
  26.  
  27. void __stdargs _CXFERR(int code)
  28. {
  29.     extern int _FPERR;
  30.     _FPERR = code;
  31. }
  32.  
  33.  
  34. /**
  35.  * DEFINES
  36.  **/
  37. #define REG(x) register __## x
  38.  
  39.  
  40. /**
  41.  * GLOBAL VARIABLES
  42.  **/
  43. static UBYTE *EngineName = "type1";
  44. static FONTREQUEST fontreq;
  45. static const char *versionstring = "$VER: type1.library.030 1.4 (C) Amish S. Dave";
  46.  
  47.  
  48. /**
  49.  * PROTOTYPES
  50.  **/
  51. struct GlyphEngine * __saveds __asm OpenEngine(REG(a6) struct Library *Type1Base);
  52. void __saveds __asm CloseEngine(REG(a0) struct GlyphEngine *engine, REG(a6) struct Library *Type1Base);
  53. ULONG __saveds __asm ObtainInfoA(REG(a0) struct GlyphEngine *engine, REG(a1) struct TagItem *tags, REG(a6) struct Library *Type1Base);
  54. ULONG __saveds __asm SetInfoA(REG(a0) struct GlyphEngine *engine, REG(a1) struct TagItem *tags, REG(a6) struct Library *Type1Base);
  55. ULONG __saveds __asm ReleaseInfoA(REG(a0) struct GlyphEngine *engine, REG(a1) struct TagItem *tags, REG(a6) struct Library *Type1Base);
  56.  
  57. static void clearfontreq(FONTREQUEST *fontreq_p);
  58. static void scantags(struct TagItem *tags);
  59.  
  60.  
  61. /**
  62.  * EXTERNAL PROTOTYPES (from type1interface.c)
  63.  **/
  64. extern void OpenType1Engine(void);
  65. extern void CloseType1Engine(void);
  66. extern unsigned long ReadType1Font(FONTREQUEST *fontreq_p);
  67. extern struct GlyphMap *GetType1GlyphMap(ULONG GlyphCode);
  68. extern void CloseType1Font(void);
  69. extern int MyQueryFontLib(char *filename, char *env, void *dest);
  70. extern unsigned long SetTransformType1Font(FONTREQUEST *fontreq_p);
  71.  
  72.  
  73. /**
  74.  * OpenEngine
  75.  **/
  76. struct GlyphEngine * __saveds __asm OpenEngine(REG(a6) struct Library *Type1Base)
  77. {
  78.     struct GlyphEngine *ge;
  79.     extern UBYTE *EngineName;
  80.  
  81.     ge = AllocVec(sizeof(struct GlyphEngine), 0L);
  82.     ge->gle_Library = Type1Base;
  83.     ge->gle_Name = EngineName;
  84.  
  85.     clearfontreq(&fontreq);
  86.  
  87.     OpenType1Engine();
  88.     return ge;
  89. }
  90.  
  91.  
  92. /**
  93.  * CloseEngine
  94.  **/
  95. void __saveds __asm CloseEngine(REG(a0) struct GlyphEngine *engine, REG(a6) struct Library *Type1Base)
  96. {
  97.     CloseType1Engine();
  98.  
  99.     FreeVec(engine);
  100.     return;
  101. }
  102.  
  103.  
  104. /**
  105.  * ObtainInfoA
  106.  **/
  107. ULONG __saveds __asm ObtainInfoA(REG(a0) struct GlyphEngine *engine, REG(a1) struct TagItem *tags, REG(a6) struct Library *Type1Base)
  108. {
  109.     struct GlyphMap **gm_p;
  110.     BOOL *IsFixed_p;
  111.     char **familyname, **fontname;
  112.  
  113.     if (gm_p = (struct GlyphMap **)GetTagData(OT_GlyphMap, NULL, tags))
  114.     {
  115.  
  116.         if (fontreq.FontDone == 0)
  117.         {
  118.             if (ReadType1Font(&fontreq) != 0)
  119.                 return (ULONG)-1;
  120.             fontreq.FontDone = 1;
  121.             fontreq.transformchanged = FALSE;
  122.         }
  123.  
  124.         if (fontreq.transformchanged == TRUE)
  125.         {
  126.             if (SetTransformType1Font(&fontreq) != 0)    
  127.                 return (ULONG)-1;
  128.             fontreq.transformchanged = FALSE;
  129.         }
  130.  
  131.         if ((*gm_p = GetType1GlyphMap(fontreq.GlyphCode)) == NULL)
  132.             return (ULONG)-1;
  133.     }
  134.  
  135.     if (IsFixed_p = (BOOL *)GetTagData(OT_IsFixed, NULL, tags))
  136.     {
  137.         if (MyQueryFontLib(fontreq.FontFileName, "isFixedPitch", (void *)IsFixed_p) != 0)
  138.             return (ULONG) -1;
  139.     }
  140.  
  141.     if (familyname = (char **)GetTagData(OT_Family, NULL, tags))
  142.     {
  143.         if (MyQueryFontLib(fontreq.FontFileName, "FamilyName", (void *)familyname) != 0)
  144.             return (ULONG) -1;
  145.     }
  146.  
  147.     if (fontname = (char **)GetTagData(OT_Spec3, NULL, tags))
  148.     {
  149.         if (MyQueryFontLib(fontreq.FontFileName, "FontName", (void *)fontname) != 0)
  150.             return (ULONG) -1;
  151.     }
  152.  
  153.     return 0;
  154. }
  155.  
  156.  
  157. /**
  158.  * SetInfoA
  159.  **/
  160. ULONG __saveds __asm SetInfoA(REG(a0) struct GlyphEngine *engine, REG(a1) struct TagItem *tags, REG(a6) struct Library *Type1Base)
  161. {
  162.     struct TagItem *otags;
  163.  
  164.     scantags(tags);
  165.  
  166.     if (otags = (struct TagItem *)GetTagData(OT_OTagList, NULL, tags))
  167.         if (GetTagData(OT_OTagList, NULL, otags) == NULL)        /* Just in case... */
  168.             scantags(otags);
  169.  
  170.     return 0;
  171. }
  172.  
  173.  
  174. /**
  175.  * ReleaseInfoA
  176.  **/
  177. ULONG __saveds __asm ReleaseInfoA(REG(a0) struct GlyphEngine *engine, REG(a1) struct TagItem *tags, REG(a6) struct Library *Type1Base)
  178. {
  179.     return 0;
  180. }
  181.  
  182.  
  183. static void clearfontreq(FONTREQUEST *fontreq_p)
  184. {
  185.     fontreq_p->FontDone = 0;
  186.     fontreq_p->GlyphCode = 0;
  187.     fontreq_p->DeviceXDPI = 0;
  188.     fontreq_p->DeviceYDPI = 0;
  189.     fontreq_p->PointHeight = 0;
  190.     fontreq_p->SetFactor = 0;
  191.     fontreq_p->PointSet = 0;
  192.     fontreq_p->RotateSin = 0.0;
  193.     fontreq_p->RotateCos = 1.0;
  194.     fontreq_p->ShearSin = 0.0;
  195.     fontreq_p->ShearCos = 1.0;
  196.  
  197.     fontreq_p->FontFileName[0] = '\0';
  198.     fontreq_p->OTagFileName[0] = '\0';
  199.     fontreq_p->AFMFileName[0] = '\0';
  200. }
  201.  
  202. #define sgn(a) (a<0?-1:a>0?1:0)
  203. #define FP2DOUBLE(fp) (sgn(fp)*((double)((abs(fp) & 0xffff0000) >> 16) + (((double)(abs(fp) & 0x0000ffff)) / 65536)))
  204.  
  205. /**
  206.  * scantags
  207.  **/
  208. static void scantags(struct TagItem *tags)
  209. {
  210.     LONG otagdata;
  211.     BOOL transformchanged = FALSE;
  212.  
  213.     if (otagdata = GetTagData(OT_OTagPath, NULL, tags))
  214.     {
  215.         clearfontreq(&fontreq);
  216.         strcpy(fontreq.OTagFileName, (char *)otagdata);
  217.         CloseType1Font();
  218.     }
  219.  
  220.     /* OT_Spec1 = the filename string of the pfb file */
  221.     if (otagdata = GetTagData(OT_Spec1 | OT_Indirect, NULL, tags))
  222.         strcpy(fontreq.FontFileName, (char *)otagdata);
  223.  
  224.     /* OT_Spec2 = the filename of the AFM file */
  225.     if (otagdata = GetTagData(OT_Spec2 | OT_Indirect, NULL, tags))
  226.         strcpy(fontreq.AFMFileName, (char *)otagdata);
  227.  
  228.     /* OT_Spec3 = the name of the font, from the FontName field of the font itself */
  229.     /* Not to be used in .otags, and not to be set.  Can be queried by an installer. */
  230.     
  231.     /* For now, assume fractional part is zero */
  232.     if (otagdata = GetTagData(OT_PointHeight, 0L, tags))
  233.     {
  234.         fontreq.PointHeight = ((ULONG)otagdata) >> 16;
  235.         transformchanged = TRUE;
  236.     }
  237.  
  238.     if (otagdata = GetTagData(OT_RotateSin, 0L, tags))
  239.     {
  240.         fontreq.RotateSin = FP2DOUBLE(otagdata);
  241.         transformchanged = TRUE;
  242.     }
  243.  
  244.     if (otagdata = GetTagData(OT_RotateCos, 0L, tags))
  245.     {
  246.         fontreq.RotateCos = FP2DOUBLE(otagdata);
  247.         transformchanged = TRUE;
  248.     }
  249.  
  250.     if (otagdata = GetTagData(OT_ShearSin, 0L, tags))
  251.     {
  252.         fontreq.ShearSin = FP2DOUBLE(otagdata);
  253.         transformchanged = TRUE;
  254.     }
  255.  
  256.     if (otagdata = GetTagData(OT_ShearCos, 0L, tags))
  257.     {
  258.         fontreq.ShearCos = FP2DOUBLE(otagdata);
  259.         transformchanged = TRUE;
  260.     }
  261.  
  262.     if (otagdata = GetTagData(OT_SetFactor, 0L, tags))
  263.     {
  264.         fontreq.SetFactor = (ULONG)otagdata;
  265.         if (otagdata == 0x00010000)
  266.             fontreq.PointSet = 0;
  267.         else
  268.             fontreq.PointSet = FP2DOUBLE(otagdata) * fontreq.PointHeight;
  269.         transformchanged = TRUE;
  270.     }
  271.  
  272.     if (otagdata = GetTagData(OT_DeviceDPI, 0L, tags))
  273.     {
  274.         fontreq.DeviceXDPI = ((ULONG)otagdata) >> 16;
  275.         fontreq.DeviceYDPI = ((ULONG)otagdata) & 0xffff;
  276.         transformchanged = TRUE;
  277.     }
  278.  
  279.     if (otagdata = GetTagData(OT_GlyphCode, 0L, tags))
  280.         fontreq.GlyphCode = (ULONG)otagdata;
  281.  
  282.     if (transformchanged == TRUE)
  283.         fontreq.transformchanged = TRUE;
  284. }
  285.  
  286.